home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 037a / tpfast40.zip / TPFBIT.ASM < prev    next >
Assembly Source File  |  1991-11-14  |  8KB  |  153 lines

  1. ;   _______________________________________________________________
  2. ;  |                                                               |
  3. ;  |            CopyRight (c) 1989,1990  Steven Lutrov             |
  4. ;  |_______________________________________________________________|____
  5. ;  |                                                               |    |
  6. ;  |  program title : fastbit.asm                                  |    | ___
  7. ;  |  author        : Steven Lutrov                                |    |    |
  8. ;  |  revision      : 4.00                                         |    |    |
  9. ;  |  date          : 1991-11-01                                   |    |    |
  10. ;  |  language      : turbo  assembler                             |    |    |
  11. ;  |                                                               |    |    |
  12. ;  |  description   : assembly functions for bit mannipulation.    |    |    |
  13. ;  |                : tested with turbo pascal ver 5.0 5.5         |    |    |
  14. ;  |                                                               |    |    |
  15. ;  |_______________________________________________________________|    |    |
  16. ;      |                                                                |    |
  17. ;      |________________________________________________________________|    |
  18. ;          |                                                                 |
  19. ;          |_________________________________________________________________|
  20. ;
  21.  
  22.  
  23. code    segment word  public
  24.  
  25. assume  cs:code
  26.  
  27.  
  28. public  bytetohex,rotatebyteleft,rotatewordleft,rotatebyteright
  29. public  rotatewordright,wordtohex
  30.  
  31.  
  32. ;-------------------------------------------------------------------------------
  33. ;function bytetohex(num :byte;): stype;
  34. ;-------------------------------------------------------------------------------
  35. ;
  36. bytetohex proc far
  37.                 push bp                         ;save bp
  38.                 mov  bp,sp                      ;set stack frame
  39.                 les  di,dword ptr[bp+8]         ;es:di pts to return string
  40.                 sub  si,si                      ;si counts chars
  41.                 mov  bl,[bp+6]                  ;get the value to convert
  42.                 mov  cl,2                       ;string length
  43.                 mov  es:[di],cl                 ;set string descriptor
  44.                 shl  cl,1                       ;cl=4 bits=one-half byte
  45. bytetohex1:     sub  bh,bh                      ;clear bh
  46.                 shl  bx,cl                      ;shift in one-half byte
  47.                 cmp  bh,10                      ;is it '0' - '9'?
  48.                 jl   bytetohex2                 ;if not, jump ahead
  49.                 add  bh,55                      ;10+55 = 'a', etc...
  50.                 jmp  short bytetohex3           ;jmp ahead
  51. bytetohex2:     add  bh,48                      ;0+48 = '0', etc...
  52. bytetohex3:     inc  di                         ;pt to next byte of strx
  53.                 mov  es:[di],bh                 ;place char in the strx
  54.                 inc  si                         ;test char counter
  55.                 cmp  si,2                       ;end of string?
  56.                 jne  bytetohex1                 ;jump if not
  57.                 pop  bp                         ;restore bp
  58.                 ret  2
  59. bytetohex endp
  60.  
  61.  
  62.  
  63. ;-------------------------------------------------------------------------------
  64. ;function rotatewordleft(num: word; nbits :byte;): word;
  65. ;-------------------------------------------------------------------------------
  66. ;
  67. rotatewordleft proc far
  68.                 mov  bx,sp                      ;set stack frame
  69.                 mov  cl,ss:[bx+4]               ;number of bits to rotate
  70.                 mov  ax,ss:[bx+6]               ;get the integer
  71.                 rol  ax,cl                      ;make the rotation
  72.                 ret  4
  73. rotatewordleft endp
  74.  
  75.  
  76. ;-------------------------------------------------------------------------------
  77. ;function rotatebyteright(num,nbits :byte;) :byte;;
  78. ;-------------------------------------------------------------------------------
  79. ;
  80. rotatebyteright proc far
  81.                 mov  bx,sp                      ;set stack frame
  82.                 mov  cl,ss:[bx+4]               ;number of bits to rotate
  83.                 mov  al,ss:[bx+6]               ;get the byte
  84.                 ror  al,cl                      ;make the rotation
  85.                 ret  4
  86. rotatebyteright endp
  87.  
  88. ;-------------------------------------------------------------------------------
  89. ;function rotatebyteleft(num,nbits :byte) :byte;;
  90. ;-------------------------------------------------------------------------------
  91. ;
  92. rotatebyteleft proc far
  93.                 mov  bx,sp                      ;set stack frame
  94.                 mov  cx,ss:[bx+4]               ;number of bits to rotate
  95.                 mov  al,ss:[bx+6]               ;get the byte
  96.                 rol  al,cl                      ;make the rotation
  97.                 ret  4
  98. rotatebyteleft endp
  99.  
  100.  
  101. ;-------------------------------------------------------------------------------
  102. ;function rotatewordright(num: word; nbits :byte;): word;
  103. ;-------------------------------------------------------------------------------
  104. ;
  105. rotatewordright proc far
  106.                 mov  bx,sp                      ;set stack frame
  107.                 mov  cl,ss:[bx+4]               ;number of bits to rotate
  108.                 mov  ax,ss:[bx+6]               ;get the integer
  109.                 ror  ax,cl                      ;make the rotation
  110.                 ret  4
  111. rotatewordright endp
  112.  
  113.  
  114.  
  115. ;-------------------------------------------------------------------------------
  116. ;function wordtohex(num: word): stype;
  117. ;-------------------------------------------------------------------------------
  118. ;
  119. wordtohex proc far
  120.                 push bp                         ;save bp
  121.                 mov  bp,sp                      ;set stack frame
  122.                 les  di,dword ptr[bp+8]         ;es:di pts to return string
  123.                 sub  si,si                      ;si counts chars
  124.                 mov  ax,[bp+6]                  ;get the value to convert
  125.                 mov  cl,4                       ;shifts one-half byte
  126.                 mov  es:[di],cl                 ;set string descriptor
  127.                 mov  bl,ah                      ;start with high byte
  128. wordtohex1:     sub  bh,bh                      ;clear bh
  129.                 shl  bx,cl                      ;shift in one-half byte
  130.                 cmp  bh,10                      ;is it '0' - '9'?
  131.                 jl   wordtohex2                 ;if not, jump ahead
  132.                 add  bh,55                      ;10+55 = 'a', etc...
  133.                 jmp  short wordtohex3           ;jmp ahead
  134. wordtohex2:     add  bh,48                      ;0+48 = '0', etc...
  135. wordtohex3:     inc  di                         ;pt to next byte of strx
  136.                 mov  es:[di],bh                 ;place char in the strx
  137.  
  138.                 inc  si                         ;test char counter
  139.                 test si,1                       ;is strx ctr odd or even?
  140.                 jnz  wordtohex1                 ;do 2nd half char if odd
  141.                 cmp  si,2                       ;another byte to do?
  142.                 jne  wordtohex4                 ;jump if not
  143.                 mov  bl,al                      ;fetch low byte
  144.                 jmp  short wordtohex1           ;start over on 2nd byte
  145. wordtohex4:     pop  bp                         ;restore bp
  146.                 ret  2
  147. wordtohex endp
  148.  
  149.  
  150. code    ends
  151.         end
  152.  
  153.